package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.domain.CommentOfComment;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    @PostMapping("/{strategyId}")
    public Object postComment(Comment comment,String imgUrl){
        comment.setTime(new Date());
        System.out.println("ok");
        commentService.save(comment,imgUrl);
        return new JSONResult();
    }
    @GetMapping("/{strategyId}")
    public Object selectStrategy(StrategyCatalogQueryObject qo){
        qo.setOrderBy("c.time desc");
        PageInfo info = commentService.selectStrategyByStrategyId(qo);
        return info;
    }
//
    @GetMapping("/comment/{id}")
    public Object selectById(@PathVariable Long id){
        Comment comment = commentService.selectById(id);
        return comment;
    }
    @PostMapping("/commentofcomment/{commentId}")
    public Object postCommentOfComment(CommentOfComment commentOfComment){
        commentService.saveCommentOfComment(commentOfComment);
        return new JSONResult();
    }
    @GetMapping("/commentofcomment/{commentId}")
    public Object getCommentOfComment(CommentQueryObject qo){
        PageInfo info = commentService.selectCommentOfCommentByCommentId(qo);
        return info;
    }
}
